home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / winsr173.zip / CMDFILES.C < prev    next >
C/C++ Source or Header  |  1992-06-03  |  61KB  |  1,963 lines

  1. /*
  2.     Command-line / Command-File Parser Routines
  3.     This module is linked as an overlay, use ENTER_OVLY and EXIT_OVLY.
  4. */
  5.  
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <float.h>
  10. #include <ctype.h>
  11. #include "fractint.h"
  12. #ifdef __TURBOC__
  13. #include <dir.h>
  14. #endif
  15.  
  16. /* routines in this module    */
  17.  
  18. void cmdfiles_overlay(void);
  19. int  cmdfiles(int argc, char *argv[]);
  20. int  load_commands(FILE *);
  21. void set_3d_defaults(void);
  22.  
  23. static int  cmdfile(FILE *,int);
  24. static int  next_command(char *,int,FILE *,char *,int *,int);
  25. static int  next_line(FILE *,char *,int);
  26. static int  cmdarg(char *,int);
  27. static void argerror(char *);
  28. static void initvars_run(void);
  29. static void initvars_restart(void);
  30. static void initvars_fractal(void);
  31. static void initvars_3d(void);
  32. static void reset_ifs_defn(void);
  33. static void parse_textcolors(char *value);
  34. static int  parse_colors(char *value);
  35. static int  parse_printer(char *value);
  36.  
  37. extern int  makedoc_msg_func(int,int);
  38.  
  39. /* variables defined by the command line/files processor */
  40. int        showdot;    /* color to show crawling graphics cursor */
  41. char    temp1[256];        /* temporary strings        */
  42. char    readname[80];        /* name of fractal input file */
  43. char    gifmask[13] = {""};
  44. char    PrintName[80]={"fract001.prn"}; /* Name for print-to-file */
  45. char    savename[80]={"fract001"};      /* save files using this name */
  46. char    autoname[80]={"auto.key"};      /* record auto keystrokes here */
  47. int    potflag=0;        /* continuous potential enabled? */
  48. int    pot16bit;        /* store 16 bit continuous potential values */
  49. int    gif87a_flag;        /* 1 if GIF87a format, 0 otherwise */
  50. int    askvideo;        /* flag for video prompting */
  51. char    floatflag;
  52. int    biomorph;        /* flag for biomorph */
  53. int    usr_biomorph;
  54. int    forcesymmetry;        /* force symmetry */
  55. int    showfile;        /* zero if file display pending */
  56. int    rflag, rseed;        /* Random number seeding flag and value */
  57. int    decomp[2];        /* Decomposition coloring */
  58. int    distest;
  59. int    distestwidth;
  60. char overwrite = 0;    /* 0 if file overwrite not allowed */
  61. int    soundflag;        /* 0 if sound is off, 1 if on */
  62. int    basehertz;        /* sound=x/y/x hertz value */
  63. int    debugflag;        /* internal use only - you didn't see this */
  64. int    timerflag;        /* you didn't see this, either */
  65. int    cyclelimit;        /* color-rotator upper limit */
  66. int    inside;         /* inside color: 1=blue     */
  67. int    fillcolor;         /* fillcolor: -1=normal     */
  68. int    outside;        /* outside color    */
  69. int    finattract;        /* finite attractor logic */
  70. int    display3d;        /* 3D display flag: 0 = OFF */
  71. int    overlay3d;        /* 3D overlay flag: 0 = OFF */
  72. int    init3d[20];        /* '3d=nn/nn/nn/...' values */
  73. int    initbatch;        /* 1 if batch run (no kbd)  */
  74. unsigned initsavetime;        /* autosave minutes        */
  75. double    initorbit[2];        /* initial orbitvalue */
  76. char    useinitorbit;        /* flag for initorbit */
  77. int    initmode;        /* initial video mode        */
  78. int    initcyclelimit;     /* initial cycle limit        */
  79. unsigned char usemag;        /* use center-mag corners   */
  80. int    bailout;        /* user input bailout value */
  81. double    inversion[3];        /* radius, xcenter, ycenter */
  82. int    rotate_lo,rotate_hi;    /* cycling color range        */
  83. int far *ranges;        /* iter->color ranges mapping */
  84. int    rangeslen = 0;        /* size of ranges array     */
  85. char far *mapdacbox = NULL;    /* map= (default colors)    */
  86. int    colorstate;        /* 0, dacbox matches default (bios or map=) */
  87.                 /* 1, dacbox matches no known defined map   */
  88.                 /* 2, dacbox matches the colorfile map        */
  89. int    colorpreloaded;     /* if dacbox preloaded for next mode select */
  90. extern int Targa_Overlay;
  91. int Targa_Out = 0;
  92. char    colorfile[80];        /* from last <l> <s> or colors=@filename    */
  93.  
  94. /* TARGA+ variables */
  95. int    TPlusFlag;        /* Use the TARGA+ if found  */
  96. int    MaxColorRes;        /* Default Color Resolution if available */
  97. int    PixelZoom;        /* TPlus Zoom Level */
  98. int    NonInterlaced;        /* Non-Interlaced video flag */
  99.  
  100. /* 3D Transparency Variables, MCP 5-30-91 */
  101. double xcoord, ycoord, zcoord, tcoord;
  102. double zzmin, zzmax;        /* initial depth corner values */
  103. double ttmin, ttmax;        /* initial time coordinates */
  104. int Transparent3D, SolidCore, MultiDrawing;
  105. int tpdepth, tptime;
  106. unsigned CoreRed, CoreGreen, CoreBlue, NumFrames;
  107.  
  108. /* AntiAliasing variables, MCP 6-6-91 */
  109. int AntiAliasing, Shadowing;
  110.  
  111. int    orbitsave = 0;        /* for IFS and LORENZ to output acrospin file */
  112. int orbit_delay;                /* clock ticks delating orbit release */
  113. extern    int invert;
  114. extern int fractype;        /* fractal type         */
  115. extern double param[4];     /* initial parameters        */
  116. extern double xxmin,xxmax;    /* initial corner values    */
  117. extern double yymin,yymax;    /* initial corner values    */
  118. extern double xx3rd,yy3rd;    /* initial corner values    */
  119. extern char usr_stdcalcmode;    /* '1', '2', 'g', 'b'       */
  120. extern int maxit;        /* max iterations        */
  121. extern int usr_periodicitycheck; /* periodicity checking  1=on,0=off */
  122. extern char usr_floatflag;    /* flag for float calcs */
  123. extern int usr_distest;     /* nonzero if distance estimator option */
  124. extern char color_lakes;    /* finite attractor flag */
  125. extern int haze;
  126. extern int RANDOMIZE;
  127. extern int Ambient;
  128. extern char light_name[];
  129. extern int BRIEF;
  130. extern int RAY;
  131.  
  132. extern unsigned char back_color[];
  133. extern unsigned char dacbox[256][3];
  134. extern struct videoinfo far videotable[];
  135. extern int fpu;
  136. extern int iit;
  137.  
  138. extern double potparam[];    /* potential parameters  */
  139. extern int Printer_Resolution, LPTNumber,
  140.        Printer_Type, Printer_Titleblock,
  141.        Printer_ColorXlat, Printer_SetScreen,
  142.        Printer_SFrequency, Printer_SAngle, Printer_SStyle,
  143.        Printer_RFrequency, Printer_RAngle, Printer_RStyle,
  144.        Printer_GFrequency, Printer_GAngle, Printer_GStyle,
  145.        Printer_BFrequency, Printer_BAngle, Printer_BStyle,
  146.        EPSFileType, ColorPS,
  147.        Print_To_File,Printer_CRLF;        /* for printer functions */
  148.  
  149. int    transparent[2];     /* transparency min/max values */
  150. int    LogFlag;        /* Logarithmic palette flag: 0 = no */
  151.  
  152. unsigned char exitmode = 3;    /* video mode on exit */
  153.  
  154. extern int video_type;
  155. extern int svga_type;           /* for forcing a specific SVGA adapter */
  156. extern int mode7text;
  157. extern int textsafe;
  158. extern int vesa_detect;
  159.  
  160. int        bios_palette;        /* set to 1 to force BIOS palette updates */
  161. int        escape_exit;         /* set to 1 to avoid the "are you sure?" screen */
  162.  
  163. extern int   viewwindow;
  164. extern float viewreduction;
  165. extern int   viewcrop;
  166. extern float finalaspectratio;
  167. extern int   viewxdots,viewydots;
  168.  
  169. extern char MAP_name[];
  170. extern int mapset;
  171.  
  172. extern int eyeseparation; /* Occular Separation */
  173. extern int glassestype;
  174. extern int xadjust; /* Convergence */
  175. extern int yadjust;
  176. extern int xtrans, ytrans; /* X,Y shift with no perspective */
  177. extern int red_crop_left, red_crop_right;
  178. extern int blue_crop_left, blue_crop_right;
  179. extern int red_bright, blue_bright;
  180. extern char showbox; /* flag to show box and vector in preview */
  181. extern char preview;        /* 3D preview mode flag */
  182. extern int previewfactor; /* Coarsness */
  183.  
  184. int first_init=1;        /* first time into cmdfiles? */
  185. static int init_rseed;
  186. static char initcorners,initparams;
  187. struct fractalspecificstuff far *curfractalspecific;
  188.  
  189. char FormFileName[80];        /* file to find (type=)formulas in */
  190. char FormName[ITEMNAMELEN+1];    /* Name of the Formula (if not null) */
  191. char LFileName[80];        /* file to find (type=)L-System's in */
  192. char LName[ITEMNAMELEN+1];    /* Name of L-System */
  193. char CommandFile[80];        /* file to find command sets in */
  194. char CommandName[ITEMNAMELEN+1];/* Name of Command set */
  195. char CommandComment1[57];    /* comments for command set */
  196. char CommandComment2[57];
  197. char IFSFileName[80];        /* file to find (type=)IFS in */
  198. char IFSName[ITEMNAMELEN+1];    /* Name of the IFS def'n (if not null) */
  199. float far *ifs_defn = NULL;    /* ifs parameters */
  200. int  ifs_changed;        /* nonzero if parameters have been edited */
  201. int  ifs_type;            /* 0=2d, 1=3d */
  202. int  slides = 0;        /* 1 autokey=play, 2 autokey=record */
  203.  
  204. unsigned char txtcolor[]={
  205.       BLUE*16+L_WHITE,      /* C_TITLE           title background */
  206.       BLUE*16+L_GREEN,      /* C_TITLE_DEV       development vsn foreground */
  207.       GREEN*16+YELLOW,      /* C_HELP_HDG        help page title line */
  208.       WHITE*16+BLACK,      /* C_HELP_BODY       help page body */
  209.       GREEN*16+GRAY,      /* C_HELP_INSTR      help page instr at bottom */
  210.       WHITE*16+BLUE,      /* C_HELP_LINK       help page links */
  211.       CYAN*16+BLUE,      /* C_HELP_CURLINK    help page current link */
  212.       WHITE*16+GRAY,      /* C_PROMPT_BKGRD    prompt/choice background */
  213.       WHITE*16+BLACK,      /* C_PROMPT_TEXT     prompt/choice extra info */
  214.       BLUE*16+WHITE,      /* C_PROMPT_LO       prompt/choice text */
  215.       BLUE*16+L_WHITE,      /* C_PROMPT_MED      prompt/choice hdg2/... */
  216.       BLUE*16+YELLOW,      /* C_PROMPT_HI       prompt/choice hdg/cur/... */
  217.       GREEN*16+L_WHITE,   /* C_PROMPT_INPUT    fullscreen_prompt input */
  218.       CYAN*16+L_WHITE,      /* C_PROMPT_CHOOSE   fullscreen_prompt choice */
  219.       MAGENTA*16+L_WHITE, /* C_CHOICE_CURRENT  fullscreen_choice input */
  220.       BLACK*16+WHITE,      /* C_CHOICE_SP_INSTR speed key bar & instr */
  221.       BLACK*16+L_MAGENTA, /* C_CHOICE_SP_KEYIN speed key value */
  222.       WHITE*16+BLUE,      /* C_GENERAL_HI      tab, thinking, IFS */
  223.       WHITE*16+BLACK,      /* C_GENERAL_MED */
  224.       WHITE*16+GRAY,      /* C_GENERAL_LO */
  225.       BLACK*16+L_WHITE,   /* C_GENERAL_INPUT */
  226.       WHITE*16+BLACK,      /* C_DVID_BKGRD      disk video */
  227.       BLACK*16+YELLOW,      /* C_DVID_HI */
  228.       BLACK*16+L_WHITE,   /* C_DVID_LO */
  229.       RED*16+L_WHITE,      /* C_STOP_ERR        stop message, error */
  230.       GREEN*16+BLACK,      /* C_STOP_INFO       stop message, info */
  231.       BLUE*16+WHITE,      /* C_TITLE_LOW       bottom lines of title screen */
  232.       GREEN*16+BLACK,      /* C_AUTHDIV1        title screen dividers */
  233.       GREEN*16+GRAY,      /* C_AUTHDIV2        title screen dividers */
  234.       BLACK*16+L_WHITE,   /* C_PRIMARY           primary authors */
  235.       BLACK*16+WHITE      /* C_CONTRIB           contributing authors */
  236.       };
  237.  
  238. extern int active_system;
  239. /* start of string literals cleanup */
  240. char s_iter[]    = "iter";
  241. char s_real[]    = "real";
  242. char s_mult[]     = "mult";
  243. char s_sum[]     = "summ";
  244. char s_imag[]    = "imag";
  245. char s_zmag[]    = "zmag";
  246. char s_bof60[]   = "bof60";
  247. char s_bof61[]   = "bof61";
  248. char s_maxiter[] =  "maxiter";
  249. char s_epscross[] =  "epsilon cross";
  250. char s_startrail[] =  "star trail";
  251. char s_normal[] =  "normal";
  252.  
  253.  
  254. void cmdfiles_overlay() { }    /* for restore_active_ovly */
  255.  
  256. /*
  257.     cmdfiles(argc,argv) process the command-line arguments
  258.         it also processes the 'sstools.ini' file and any
  259.         indirect files ('fractint @myfile')
  260. */
  261.  
  262. int cmdfiles(int argc,char *argv[])
  263. {
  264.    int       i;
  265.    char    curarg[141];
  266.    char    tempstring[101];
  267.    char    *sptr;
  268.    FILE    *initfile;
  269.  
  270.    ENTER_OVLY(OVLY_CMDFILES);
  271.  
  272.    if (first_init) initvars_run();    /* once per run initialization */
  273.    initvars_restart();            /* <ins> key initialization */
  274.    initvars_fractal();            /* image initialization */
  275.  
  276.    findpath("sstools.ini", tempstring); /* look for SSTOOLS.INI */
  277.    if (tempstring[0] != 0)        /* found it! */
  278.       if ((initfile = fopen(tempstring,"r")) != NULL)
  279.      cmdfile(initfile,1);        /* process it */
  280.  
  281.    for (i = 1; i < argc; i++) {     /* cycle through args */
  282.       strcpy(curarg,argv[i]);
  283.       if (curarg[0] == ';')             /* start of comments? */
  284.      break;
  285.       if (curarg[0] != '@') {           /* simple command? */
  286.      if (strchr(curarg,'=') == NULL) { /* not xxx=yyy, so check for gif */
  287.         strcpy(tempstring,curarg);
  288.         if (strchr(curarg,'.') == NULL)
  289.            strcat(tempstring,".gif");
  290.         if ((initfile = fopen(tempstring,"rb"))) {
  291.            fread(tempstring,6,1,initfile);
  292.            if ( tempstring[0] == 'G'
  293.          && tempstring[1] == 'I'
  294.          && tempstring[2] == 'F'
  295.          && tempstring[3] >= '8' && tempstring[3] <= '9'
  296.          && tempstring[4] >= '0' && tempstring[4] <= '9') {
  297.           strcpy(readname,curarg);
  298.           curarg[0] = showfile = 0;
  299.           }
  300.            fclose(initfile);
  301.            }
  302.         }
  303.      if (curarg[0])
  304.         cmdarg(curarg,0);        /* process simple command */
  305.      }
  306.       else if ((sptr = strchr(curarg,'/'))) { /* @filename/setname? */
  307.      *sptr = 0;
  308.      strcpy(CommandFile,&curarg[1]);
  309.      strcpy(CommandName,sptr+1);
  310.      find_file_item(CommandFile,CommandName,&initfile);
  311.      cmdfile(initfile,3);
  312.      }
  313.       else {                /* @filename */
  314.      if ((initfile = fopen(&curarg[1],"r")) == NULL)
  315.         argerror(curarg);
  316.      cmdfile(initfile,0);
  317.      }
  318.       }
  319.  
  320.    if (first_init == 0) {
  321.       initmode = -1; /* don't set video when <ins> key used */
  322.       showfile = 1;  /* nor startup image file            */
  323.       }
  324.  
  325.    first_init = 0;
  326.    EXIT_OVLY;
  327.    return(0);
  328. }
  329.  
  330.  
  331. int load_commands(FILE *infile)
  332. {
  333.    /* when called, file is open in binary mode, positioned at the */
  334.    /* '(' or '{' following the desired parameter set's name       */
  335.    int ret;
  336.    ENTER_OVLY(OVLY_CMDFILES);
  337.    initcorners = initparams = 0; /* reset flags for type= */
  338.    ret = cmdfile(infile,2);
  339.    EXIT_OVLY;
  340.    return ret;
  341. }
  342.  
  343.  
  344. static void initvars_run()        /* once per run init */
  345. {
  346.    init_rseed = (int)time(NULL);
  347. }
  348.  
  349. static void initvars_restart()        /* <ins> key init */
  350. {
  351.    gif87a_flag = 0;            /* turn on GIF89a processing */
  352.    askvideo = 1;            /* turn on video-prompt flag */
  353.    overwrite = 0;            /* don't overwrite           */
  354.    soundflag = -1;            /* sound is on             */
  355.    basehertz = 440;            /* basic hertz rate         */
  356.    initbatch = 0;            /* not in batch mode         */
  357.    initsavetime = 0;            /* no auto-save          */
  358.    initmode = -1;            /* no initial video mode     */
  359.    viewwindow = 0;            /* no view window         */
  360.    viewreduction = 4.2;
  361.    viewcrop = 1;
  362.    finalaspectratio = SCREENASPECT;
  363.    viewxdots = viewydots = 0;
  364.    orbit_delay = 0;                     /* full speed orbits */
  365.    debugflag = 0;            /* debugging flag(s) are off */
  366.    timerflag = 0;            /* timer flags are off         */
  367.    strcpy(FormFileName,"fractint.frm"); /* default formula file      */
  368.    FormName[0] = 0;
  369.    strcpy(LFileName,"fractint.l");
  370.    LName[0] = 0;
  371.    strcpy(CommandFile,"fractint.par");
  372.    CommandName[0] = CommandComment1[0] = CommandComment2[0] = 0;
  373.    strcpy(IFSFileName,"fractint.ifs");
  374.    IFSName[0] = 0;
  375.    reset_ifs_defn();
  376.    rflag = 0;                /* not a fixed srand() seed */
  377.    rseed = init_rseed;
  378.    strcpy(readname,".\\");              /* initially current directory */
  379.    showfile = 1;
  380.    /* next should perhaps be fractal re-init, not just <ins> ? */
  381.    initcyclelimit=55;            /* spin-DAC default speed limit */
  382.    mapset = 0;                /* no map= name active */
  383.    if (mapdacbox) {
  384.       farmemfree(mapdacbox);
  385.       mapdacbox = NULL;
  386.       }
  387.    TPlusFlag = 1;
  388.    MaxColorRes = 8;
  389.    PixelZoom = 0;
  390.    NonInterlaced = 0;
  391.  
  392.    Transparent3D = 0;
  393.    SolidCore = 1;
  394.    CoreRed   = 128;
  395.    CoreGreen = 128;
  396.    CoreBlue  = 128;
  397.    zzmin = -1.5;
  398.    zzmax = 1.5;
  399.    ttmin = 0.0;
  400.    ttmax = 0.0;
  401.    NumFrames = 1;
  402.    tpdepth = tptime = 0;
  403.  
  404.    AntiAliasing = 0;
  405.    Shadowing = 0;
  406.  
  407.    Printer_Type = 2;            /* assume an IBM/EPSON      */
  408.    Printer_Resolution = 60;        /* assume low resolution  */
  409.    Printer_Titleblock = 0;        /* assume no title block  */
  410.    Printer_ColorXlat = 0;        /* assume positive image  */
  411.    Printer_SetScreen = 0;               /* assume default screen  */
  412.    Printer_SFrequency = 45;             /* New screen frequency K */
  413.    Printer_SAngle = 45;                 /* New screen angle     K */
  414.    Printer_SStyle = 1;                  /* New screen style     K */
  415.    Printer_RFrequency = 45;             /* New screen frequency R */
  416.    Printer_RAngle = 75;                 /* New screen angle     R */
  417.    Printer_RStyle = 1;                  /* New screen style     R */
  418.    Printer_GFrequency = 45;             /* New screen frequency G */
  419.    Printer_GAngle = 15;                 /* New screen angle     G */
  420.    Printer_GStyle = 1;                  /* New screen style     G */
  421.    Printer_BFrequency = 45;             /* New screen frequency B */
  422.    Printer_BAngle = 0;                  /* New screen angle     B */
  423.    Printer_BStyle = 1;                  /* New screen style     B */
  424.    Print_To_File = 0;            /* No print-to-file      */
  425.    Printer_CRLF = 0;            /* Assume CR+LF       */
  426.    EPSFileType = 0;            /* Assume no save to .EPS */
  427.    LPTNumber = 1;            /* assume LPT1 */
  428.    ColorPS = 0;                         /* Assume NO Color PostScr*/
  429.  
  430. }
  431.  
  432. static void initvars_fractal()        /* init vars affecting calculation */
  433. {
  434.    int i;
  435.    bios_palette = 0;                    /* don't force use of a BIOS palette */
  436.    escape_exit = 0;                     /* don't disable the "are you sure?" screen */
  437.    usr_periodicitycheck = 1;        /* turn on periodicity      */
  438.    inside = 1;                /* inside color = blue      */
  439.    fillcolor = -1;            /* no special fill color */
  440.    usr_biomorph = -1;            /* turn off biomorph flag */
  441.    outside = -1;            /* outside color = -1 (not used) */
  442.    maxit = 150;             /* initial maxiter      */
  443.    usr_stdcalcmode = 'g';               /* initial solid-guessing */
  444.    usr_floatflag = 0;            /* turn off the float flag */
  445.    finattract = 0;            /* disable finite attractor logic */
  446.    fractype = 0;            /* initial type Set flag  */
  447.    curfractalspecific = &fractalspecific[0];
  448.    initcorners = initparams = 0;
  449.    bailout = 0;             /* no user-entered bailout */
  450.    useinitorbit = 0;
  451.    for (i = 0; i < 4; i++) param[i] = 0.0;     /* initial parameter values */
  452.    for (i = 0; i < 3; i++) potparam[i]    = 0.0; /* initial potential values */
  453.    for (i = 0; i < 3; i++) inversion[i] = 0.0;    /* initial invert values */
  454.    initorbit[0] = initorbit[1] = 0.0;    /* initial orbit values */
  455.    invert = 0;
  456.    decomp[0] = decomp[1] = 0;
  457.    usr_distest = 0;
  458.    distestwidth = 71;
  459.    forcesymmetry = 999;         /* symmetry not forced */
  460.    xx3rd = xxmin = -2.5; xxmax = 1.5;    /* initial corner values  */
  461.    yy3rd = yymin = -1.5; yymax = 1.5;    /* initial corner values  */
  462.    pot16bit = potflag = 0;
  463.    LogFlag = 0;             /* no logarithmic palette */
  464.    set_trig_array(0,"sin");             /* trigfn defaults */
  465.    set_trig_array(1,"sqr");
  466.    set_trig_array(2,"sinh");
  467.    set_trig_array(3,"cosh");
  468.    if (rangeslen) {
  469.       farmemfree((char far *)ranges);
  470.       rangeslen = 0;
  471.       }
  472.    usemag = 0;                /* use corners, not center-mag */
  473.  
  474.    colorstate = colorpreloaded = 0;
  475.    rotate_lo = 1; rotate_hi = 255;    /* color cycling default range */
  476.  
  477.    display3d = 0;            /* 3D display is off        */
  478.    overlay3d = 0;            /* 3D overlay is off        */
  479.  
  480.    initvars_3d();
  481. }
  482.  
  483. static void initvars_3d()        /* init vars affecting 3d */
  484. {
  485.    RAY     = 0;
  486.    BRIEF   = 0;
  487.    SPHERE = FALSE;
  488.    preview = 0;
  489.    showbox = 0;
  490.    xadjust = 0;
  491.    yadjust = 0;
  492.    eyeseparation = 0;
  493.    glassestype = 0;
  494.    previewfactor = 20;
  495.    red_crop_left   = 4;
  496.    red_crop_right  = 0;
  497.    blue_crop_left  = 0;
  498.    blue_crop_right = 4;
  499.    red_bright      = 80;
  500.    blue_bright     = 100;
  501.    transparent[0] = transparent[1] = 0; /* no min/max transparency */
  502.    set_3d_defaults();
  503. }
  504.  
  505. static void reset_ifs_defn()
  506. {
  507.    if (ifs_defn) {
  508.       farmemfree((char far *)ifs_defn);
  509.       ifs_defn = NULL;
  510.       }
  511. }
  512.  
  513.  
  514. static int cmdfile(FILE *handle,int mode)
  515.    /* mode = 0 command line @filename          */
  516.    /*         1 sstools.ini              */
  517.    /*         2 <@> command after startup      */
  518.    /*         3 command line @filename/setname */
  519. {
  520.    /* note that cmdfile could be open as text OR as binary */
  521.    /* binary is used in @ command processing for reasonable speed note/point */
  522.    int i;
  523.    int lineoffset = 0;
  524.    int changeflag = 0; /* &1 fractal stuff chgd, &2 3d stuff chgd */
  525.    char linebuf[513],cmdbuf[1001];
  526.    if (mode == 2 || mode == 3) {
  527.       while ((i = getc(handle)) != '{' && i != EOF) { }
  528.       CommandComment1[0] = CommandComment2[0] = 0;
  529.       }
  530.    linebuf[0] = 0;
  531.    while (next_command(cmdbuf,1000,handle,linebuf,&lineoffset,mode) > 0) {
  532.       if ((mode == 2 || mode == 3) && strcmp(cmdbuf,"}") == 0) break;
  533.       if ((i = cmdarg(cmdbuf,mode)) < 0) break;
  534.       changeflag |= i;
  535.       }
  536.    fclose(handle);
  537.    return changeflag;
  538. }
  539.  
  540. static int next_command(char *cmdbuf,int maxlen,
  541.               FILE *handle,char *linebuf,int *lineoffset,int mode)
  542. {
  543.    int cmdlen = 0;
  544.    char *lineptr;
  545.    lineptr = linebuf + *lineoffset;
  546.    while(1) {
  547.       while (*lineptr <= ' ' || *lineptr == ';') {
  548.      if (cmdlen) {            /* space or ; marks end of command */
  549.         cmdbuf[cmdlen] = 0;
  550.         *lineoffset = lineptr - linebuf;
  551.         return cmdlen;
  552.         }
  553.      while (*lineptr && *lineptr <= ' ')
  554.         ++lineptr;            /* skip spaces and tabs */
  555.      if (*lineptr == ';' || *lineptr == 0) {
  556.         if (*lineptr == ';'
  557.           && (mode == 2 || mode == 3)
  558.           && (CommandComment1[0] == 0 || CommandComment2[0] == 0)) {
  559.            /* save comment */
  560.            while (*(++lineptr)
  561.          && (*lineptr == ' ' || *lineptr == '\t')) { }
  562.            if (*lineptr) {
  563.           if (strlen(lineptr) > 56)
  564.              *(lineptr+56) = 0;
  565.           if (CommandComment1[0] == 0)
  566.              strcpy(CommandComment1,lineptr);
  567.           else
  568.              strcpy(CommandComment2,lineptr);
  569.           }
  570.            }
  571.         if (next_line(handle,linebuf,mode) != 0)
  572.            return(-1); /* eof */
  573.         lineptr = linebuf; /* start new line */
  574.         }
  575.      }
  576.       if (*lineptr == '\\'              /* continuation onto next line? */
  577.     && *(lineptr+1) == 0) {
  578.      if (next_line(handle,linebuf,mode) != 0) {
  579.         argerror(cmdbuf);        /* missing continuation */
  580.         return(-1);
  581.         }
  582.      lineptr = linebuf;
  583.      while (*lineptr && *lineptr <= ' ')
  584.         ++lineptr;            /* skip white space @ start next line */
  585.      continue;            /* loop to check end of line again */
  586.      }
  587.       cmdbuf[cmdlen] = *(lineptr++);    /* copy character to command buffer */
  588.       if (++cmdlen >= maxlen) {     /* command too long? */
  589.      argerror(cmdbuf);
  590.      return(-1);
  591.      }
  592.       }
  593. }
  594.  
  595. static int next_line(FILE *handle,char *linebuf,int mode)
  596. {
  597.    int toolssection;
  598.    char tmpbuf[10];
  599.    toolssection = 0;
  600.    while (file_gets(linebuf,512,handle) >= 0) {
  601.       if (mode == 1 && linebuf[0] == '[') {     /* check for [fractint] */
  602.      strncpy(tmpbuf,&linebuf[1],9);
  603.      tmpbuf[9] = 0;
  604.      strlwr(tmpbuf);
  605.      toolssection = strncmp(tmpbuf,"fractint]",9);
  606.      continue;                /* skip tools section heading */
  607.      }
  608.       if (toolssection == 0) return(0);
  609.       }
  610.    return(-1);
  611. }
  612.  
  613.  
  614. /*
  615.   cmdarg(string,mode) processes a single command-line/command-file argument
  616.     return:
  617.       -1 error, >= 0 ok
  618.       if ok, return value:
  619.     | 1 means fractal parm has been set
  620.     | 2 means 3d parm has been set
  621.     | 4 means 3d=yes specified
  622.     | 8 means reset specified
  623. */
  624.  
  625. static int cmdarg(char *curarg,int mode) /* process a single argument */
  626. {
  627.    char    variable[21];        /* variable name goes here   */
  628.    char    *value;            /* pointer to variable value */
  629.    int       valuelen;            /* length of value         */
  630.    int       numval;            /* numeric value of arg      */
  631. #define NONNUMERIC -32767
  632.    char    charval;            /* first character of arg    */
  633.    int       yesnoval;            /* 0 if 'n', 1 if 'y', -1 if not */
  634.    double  ftemp;
  635.    int       i, j, k, l;
  636.    char    *argptr,*argptr2;
  637.    int       totparms;            /* # of / delimited parms    */
  638.    int       intparms;            /* # of / delimited ints     */
  639.    int       floatparms;            /* # of / delimited floats   */
  640.    int       intval[64];            /* pre-parsed integer parms  */
  641.    double  floatval[16];        /* pre-parsed floating parms */
  642.    char    tmpc;
  643.    int       lastarg;
  644.  
  645.    argptr = curarg;
  646.    while (*argptr) {            /* convert to lower case */
  647.       if (*argptr >= 'A' && *argptr <= 'Z')
  648.      *argptr += 'a' - 'A';
  649.       if (*argptr == '=' && strncmp(curarg,"colors=",7) == 0)
  650.      break;             /* don't convert colors=value */
  651.       ++argptr;
  652.       }
  653.  
  654.    if ((value = strchr(&curarg[1],'='))) {
  655.       if ((j = (value++) - curarg) > 1 && curarg[j-1] == ':')
  656.      --j;                /* treat := same as =      */
  657.       }
  658.    else
  659.       value = curarg + (j = strlen(curarg));
  660.    if (j > 20) goto badarg;        /* keyword too long */
  661.    strncpy(variable,curarg,j);        /* get the variable name  */
  662.    variable[j] = 0;            /* truncate variable name */
  663.    valuelen = strlen(value);        /* note value's length    */
  664.    charval = value[0];            /* first letter of value  */
  665.    yesnoval = -1;            /* note yes|no value      */
  666.    if (charval == 'n') yesnoval = 0;
  667.    if (charval == 'y') yesnoval = 1;
  668.  
  669.    argptr = value;
  670.    numval = totparms = intparms = floatparms = 0;
  671.    while (*argptr) {            /* count and pre-parse parms */
  672.       lastarg = 0;
  673.       if ((argptr2 = strchr(argptr,'/')) == NULL) {     /* find next '/' */
  674.      argptr2 = argptr + strlen(argptr);
  675.      *argptr2 = '/';
  676.      lastarg = 1;
  677.      }
  678.       if (totparms == 0) numval = NONNUMERIC;
  679.       i = -1;
  680.       if (sscanf(argptr,"%d%c",&j,&tmpc) > 0            /* got an integer */
  681.     && tmpc == '/') {
  682.      ++floatparms; ++intparms;
  683.      if (totparms < 16) floatval[totparms] = j;
  684.      if (totparms < 64) intval[totparms] = j;
  685.      if (totparms == 0) numval = j;
  686.      }
  687.       else if (sscanf(argptr,"%lg%c",&ftemp,&tmpc) > 0  /* got a float */
  688.          && tmpc == '/') {
  689.      ++floatparms;
  690.      if (totparms < 16) floatval[totparms] = ftemp;
  691.      }
  692.       ++totparms;
  693.       argptr = argptr2;                 /* on to the next */
  694.       if (lastarg)
  695.      *argptr = 0;
  696.       else
  697.      ++argptr;
  698.       }
  699.  
  700.    if (mode != 2) {    /* these commands are allowed only at startup */
  701.  
  702.       if (strcmp(variable,"batch") == 0 ) {     /* batch=?      */
  703.      if (yesnoval < 0) goto badarg;
  704.      initbatch = yesnoval;
  705.      return 3;
  706.      }
  707.  
  708.       if (strcmp(variable,"adapter") == 0 ) {   /* adapter==?     */
  709.  
  710.          if (strncmp(value,"aheada",6) == 0) svga_type = 1;
  711.          if (strncmp(value,"ati"   ,3) == 0) svga_type = 2;
  712.          if (strncmp(value,"chi"   ,3) == 0) svga_type = 3;
  713.          if (strncmp(value,"eve"   ,3) == 0) svga_type = 4;
  714.          if (strncmp(value,"gen"   ,3) == 0) svga_type = 5;
  715.          if (strncmp(value,"ncr"   ,3) == 0) svga_type = 6;
  716.          if (strncmp(value,"oak"   ,3) == 0) svga_type = 7;
  717.          if (strncmp(value,"par"   ,3) == 0) svga_type = 8;
  718.          if (strncmp(value,"tri"   ,3) == 0) svga_type = 9;
  719.          if (strncmp(value,"tseng3",6) == 0) svga_type = 10;
  720.          if (strncmp(value,"tseng4",6) == 0) svga_type = 11;
  721.          if (strncmp(value,"vid"   ,3) == 0) svga_type = 12;
  722.          if (strncmp(value,"aheadb",6) == 0) svga_type = 13;
  723.          if (strncmp(value,"null"  ,4) == 0) svga_type = 14; /* for testing only */
  724.          if (svga_type != 0) return 3;
  725.  
  726.      video_type = 5;            /* assume video=vga */
  727.      if (strcmp(value,"egamono") == 0) {
  728.         video_type = 3;
  729.         mode7text = 1;
  730.         }
  731.      else if (strcmp(value,"hgc")) {             /* video = hgc */
  732.         video_type = 1;
  733.         mode7text = 1;
  734.         }
  735.      else if (strcmp(value,"ega"))               /* video = ega */
  736.         video_type = 3;
  737.      else if (strcmp(value,"cga"))               /* video = cga */
  738.         video_type = 2;
  739.      else if (strcmp(value,"mcga"))              /* video = mcga */
  740.         video_type = 4;
  741.      else if (strcmp(value,"vga"))               /* video = vga */
  742.         video_type = 5;
  743.      else
  744.         goto badarg;
  745.      return 3;
  746.      }
  747.  
  748.       if (strcmp(variable,"textsafe") == 0 ) {  /* textsafe==? */
  749.      if (first_init) {
  750.         if (charval == 'n') /* no */
  751.            textsafe = 2;
  752.         else if (charval == 'y') /* yes */
  753.            textsafe = 1;
  754.         else if (charval == 'b') /* bios */
  755.            textsafe = 3;
  756.         else if (charval == 's') /* save */
  757.            textsafe = 4;
  758.         else
  759.            goto badarg;
  760.         }
  761.      return 3;
  762.      }
  763.  
  764.       if (strcmp(variable, "vesadetect") == 0) {
  765.      if (yesnoval < 0) goto badarg;
  766.      vesa_detect = yesnoval;
  767.      return 3;
  768.      }
  769.  
  770.       if (strcmp(variable, "biospalette") == 0) {
  771.          if (yesnoval < 0) goto badarg;
  772.          bios_palette = yesnoval;
  773.          return 3;
  774.          }
  775.  
  776.       if (strcmp(variable, "exitnoask") == 0) {
  777.          if (yesnoval < 0) goto badarg;
  778.          escape_exit = yesnoval;
  779.          return 3;
  780.          }
  781.  
  782.       if (strcmp(variable,"fpu") == 0) {
  783.      if (strcmp(value,"iit") == 0) {
  784.         fpu = 387;
  785.         iit = 1;
  786.         return 0;
  787.         }
  788.      if (strcmp(value,"noiit") == 0) {
  789.         iit = -2;
  790.         return 0;
  791.         }
  792.      if (strcmp(value,"387") == 0) {
  793.         fpu = 387;
  794.         iit = -2;
  795.         return 0;
  796.         }
  797.      goto badarg;
  798.      }
  799.  
  800.       if (strcmp(variable,"makedoc") == 0) {
  801.      print_document(*value ? value : "fractint.doc", makedoc_msg_func, 0);
  802. #ifndef WINFRACT
  803.      goodbye();
  804. #endif
  805.      }
  806.  
  807.       } /* end of commands allowed only at startup */
  808.  
  809.    if (strcmp(variable,"reset") == 0) {
  810.       initvars_fractal();
  811.       return 9;
  812.       }
  813.  
  814.    if (strcmp(variable,"filename") == 0) {      /* filename=?     */
  815.       if (charval == '.') {
  816.      if (valuelen > 4) goto badarg;
  817.      gifmask[0] = '*';
  818.      gifmask[1] = 0;
  819.      strcat(gifmask,value);
  820.      return 0;
  821.      }
  822.       if (valuelen > 79) goto badarg;
  823.       if (mode == 2 && display3d == 0) /* can't do this in @ command */
  824.      goto badarg;
  825.       strcpy(readname,value);
  826.       showfile = 0;
  827.       return 3;
  828.       }
  829.  
  830.    if (strcmp(variable,"video") == 0) {         /* video=? */
  831.       if (active_system == 0) {
  832.      if ((k = check_vidmode_keyname(value)) == 0) goto badarg;
  833.      initmode = -1;
  834.      for (i = 0; i < MAXVIDEOTABLE; ++i) {
  835.         if (videotable[i].keynum == k) {
  836.            initmode = i;
  837.            break;
  838.            }
  839.         }
  840.      if (initmode == -1) goto badarg;
  841.      }
  842.       return 3;
  843.       }
  844.  
  845.    if (strcmp(variable,"map") == 0 ) {         /* map=, set default colors */
  846.       if (valuelen > 79 || SetColorPaletteName(value) != 0) goto badarg;
  847.       mapset = 1;
  848.       strcpy(MAP_name,value);
  849.       return 0;
  850.       }
  851.  
  852.    if (strcmp(variable,"colors") == 0) {       /* colors=, set current colors */
  853.       if (parse_colors(value) < 0) goto badarg;
  854.       return 0;
  855.       }
  856.  
  857.    if (strcmp(variable, "tplus") == 0) {       /* Use the TARGA+ if found? */
  858.       if (yesnoval < 0) goto badarg;
  859.       TPlusFlag = yesnoval;
  860.       return 0;
  861.       }
  862.  
  863.    if (strcmp(variable, "noninterlaced") == 0) {
  864.       if (yesnoval < 0) goto badarg;
  865.       NonInterlaced = yesnoval;
  866.       return 0;
  867.       }
  868.  
  869.    if (strcmp(variable, "maxcolorres") == 0) { /* Change default color resolution */
  870.       if (numval == 1 || numval == 4 || numval == 8 ||
  871.             numval == 16 || numval == 24) {
  872.      MaxColorRes = numval;
  873.      return 0;
  874.      }
  875.       goto badarg;
  876.       }
  877.  
  878.    if (strcmp(variable, "pixelzoom") == 0) {
  879.       if (numval < 5)
  880.      PixelZoom = numval;
  881.       return 0;
  882.       }
  883.  
  884.    /* keep this for backward compatibility */
  885.    if (strcmp(variable,"warn") == 0 ) {         /* warn=? */
  886.       if (yesnoval < 0) goto badarg;
  887.       overwrite = yesnoval ^ 1;
  888.       return 0;
  889.       }
  890.    if (strcmp(variable,"overwrite") == 0 ) {    /* overwrite=? */
  891.       if (yesnoval < 0) goto badarg;
  892.       overwrite = yesnoval;
  893.       return 0;
  894.       }
  895.  
  896.    if (strcmp(variable,"gif87a") == 0 ) {       /* gif87a=? */
  897.       if (yesnoval < 0) goto badarg;
  898.       gif87a_flag = yesnoval;
  899.       return 0;
  900.       }
  901.  
  902.    if (strcmp(variable,"savetime") == 0) {      /* savetime=? */
  903.       initsavetime = numval;
  904.       return 0;
  905.       }
  906.  
  907.    if (strcmp(variable,"autokey") == 0) {       /* autokey=? */
  908.       if (strcmp(value,"record")==0)
  909.      slides=2;
  910.       else if (strcmp(value,"play")==0)
  911.      slides=1;
  912.       else
  913.      goto badarg;
  914.       return 0;
  915.       }
  916.  
  917.    if(strcmp(variable, "solidcore") == 0) {
  918.       SolidCore = yesnoval;
  919.       return(0);
  920.       }
  921.  
  922.    if(strcmp(variable, "antialias") == 0) {
  923.       if(numval < 0 || numval > 8)
  924.      goto badarg;
  925.       AntiAliasing = numval;
  926.       return(0);
  927.       }
  928.  
  929.    if(strcmp(variable, "transparent3d") == 0) {
  930.       Transparent3D = yesnoval;
  931.       return(0);
  932.       }
  933.  
  934.    if(strcmp(variable, "corecolor") == 0) {
  935.       if(floatparms != totparms || totparms != 3)
  936.      goto badarg;
  937.       CoreRed    = (int)floatval[0];
  938.       CoreGreen = (int)floatval[1];
  939.       CoreBlue    = (int)floatval[2];
  940.       return(0);
  941.       }
  942.  
  943.    if(strcmp(variable, "mdcorners") == 0) {
  944.       if(floatparms != totparms || totparms < 2 || totparms > 4)
  945.      goto badarg;
  946.       zzmin = floatval[0];
  947.       zzmax = floatval[1];
  948.       if(totparms >= 3)
  949.      ttmin = floatval[2];
  950.       if(totparms == 4)
  951.      ttmax = floatval[3];
  952.       return(0);
  953.       }
  954.  
  955.    if(strcmp(variable, "numframes") == 0) {
  956.       NumFrames = numval;
  957.       return(0);
  958.       }
  959.  
  960.    if (strcmp(variable,"autokeyname") == 0) {   /* autokeyname=? */
  961.       strcpy(autoname,value);
  962.       return 0;
  963.       }
  964.  
  965.    if (strcmp(variable,"type") == 0 ) {         /* type=? */
  966.       if (value[valuelen-1] == '*')
  967.      value[--valuelen] = 0;
  968.       /* kludge because type ifs3d has an asterisk in front */
  969.       if(strcmp(value,"ifs3d")==0)
  970.          value[3]=0;
  971.       for (k = 0; fractalspecific[k].name != NULL; k++)
  972.      if (strcmp(value,fractalspecific[k].name) == 0)
  973.         break;
  974.       if (fractalspecific[k].name == NULL) goto badarg;
  975.       curfractalspecific = &fractalspecific[fractype = k];
  976.       if (initcorners == 0) {
  977.      xx3rd = xxmin = curfractalspecific->xmin;
  978.      xxmax           = curfractalspecific->xmax;
  979.      yy3rd = yymin = curfractalspecific->ymin;
  980.      yymax           = curfractalspecific->ymax;
  981.      }
  982.       if (initparams == 0)
  983.      for (k = 0; k < 4; ++k) {
  984.         param[k] = curfractalspecific->paramvalue[k];
  985.         roundfloatd(¶m[k]);
  986.         }
  987.       return 1;
  988.       }
  989.  
  990.    if (strcmp(variable,"inside") == 0 ) {       /* inside=? */
  991.       if(strcmp(value,s_zmag)==0)
  992.      inside = -59;
  993.       else if(strcmp(value,s_bof60)==0)
  994.      inside = -60;
  995.       else if(strcmp(value,s_bof61)==0)
  996.      inside = -61;
  997.       else if(strncmp(value,s_epscross,3)==0)
  998.      inside = -100;
  999.       else if(strncmp(value,s_startrail,4)==0)
  1000.      inside = -101;
  1001.       else if(strcmp(value,s_maxiter)==0)
  1002.      inside = -1;
  1003.       else if(numval == NONNUMERIC)
  1004.      goto badarg;
  1005.       else
  1006.      inside = numval;
  1007.       return 1;
  1008.       }
  1009.    if (strcmp(variable,"fillcolor") == 0 ) {       /* fillcolor */
  1010.       if(strcmp(value,s_normal)==0)
  1011.      fillcolor = -1;
  1012.       else if(numval == NONNUMERIC)
  1013.      goto badarg;
  1014.       else
  1015.      fillcolor = numval;
  1016.       return 1;
  1017.       }
  1018.  
  1019.    if (strcmp(variable,"finattract") == 0 ) {   /* finattract=? */
  1020.       if (yesnoval < 0) goto badarg;
  1021.       finattract = yesnoval;
  1022.       return 1;
  1023.       }
  1024.  
  1025.    if (strcmp(variable,"function") == 0) {      /* function=?,? */
  1026.       k = 0;
  1027.       while (*value && k < 4) {
  1028.      if(set_trig_array(k++,value)) goto badarg;
  1029.      if ((value = strchr(value,'/')) == NULL) break;
  1030.      ++value;
  1031.      }
  1032.       return 1;
  1033.       }
  1034.  
  1035.    if (strcmp(variable,"outside") == 0 ) {      /* outside=? */
  1036.       if(strcmp(value,s_iter)==0)
  1037.      outside = -1;
  1038.       if(strcmp(value,s_real)==0)
  1039.      outside = -2;
  1040.       else if(strcmp(value,s_imag)==0)
  1041.      outside = -3;
  1042.       else if(strcmp(value,s_mult)==0)
  1043.      outside = -4;
  1044.       else if(strcmp(value,s_sum)==0)
  1045.      outside = -5;
  1046.  
  1047.       else if(numval == NONNUMERIC)
  1048.      goto badarg;
  1049.       else if(numval < -5 || numval > 255) goto badarg;
  1050.       else outside = numval;
  1051.       return 1;
  1052.       }
  1053.  
  1054.    if (strcmp(variable,s_maxiter) == 0) {       /* maxiter=? */
  1055.       if (numval < 2) goto badarg;
  1056.       maxit = numval;
  1057.       return 1;
  1058.       }
  1059.  
  1060.    if (strcmp(variable,"iterincr") == 0)        /* iterincr=? */
  1061.       return 0;
  1062.  
  1063.    if (strcmp(variable,"passes") == 0) {        /* passes=? */
  1064.       if ( charval != '1' && charval != '2'
  1065.     && charval != 'g' && charval != 'b'
  1066.     && charval != 't')
  1067.      goto badarg;
  1068.       usr_stdcalcmode = charval;
  1069.       return 1;
  1070.       }
  1071.  
  1072.    if (strcmp(variable,"cyclelimit") == 0 ) {   /* cyclelimit=? */
  1073.       if (numval <= 1 || numval > 256) goto badarg;
  1074.       initcyclelimit = numval;
  1075.       return 0;
  1076.       }
  1077.  
  1078.    if (strcmp(variable,"cyclerange") == 0) {
  1079.       if (totparms < 2) intval[1] = 255;
  1080.       if (totparms < 1) intval[0] = 1;
  1081.       if (totparms != intparms
  1082.     || intval[0] < 0 || intval[1] > 255 || intval[0] > intval[1])
  1083.      goto badarg;
  1084.       rotate_lo = intval[0];
  1085.       rotate_hi = intval[1];
  1086.       return 0;
  1087.       }
  1088.  
  1089.    if (strcmp(variable,"ranges") == 0) {
  1090.       int i,j,entries,prev;
  1091.       int tmpranges[128];
  1092.       if (totparms != intparms) goto badarg;
  1093.       entries = prev = i = 0;
  1094.       while (i < totparms) {
  1095.      if ((j = intval[i++]) < 0) { /* striping */
  1096.         if ((j = 0-j) < 1 || j >= 16384 || i >= totparms) goto badarg;
  1097.         tmpranges[entries++] = -1; /* {-1,width,limit} for striping */
  1098.         tmpranges[entries++] = j;
  1099.         j = intval[i++];
  1100.         }
  1101.      if (j < prev) goto badarg;
  1102.      tmpranges[entries++] = prev = j;
  1103.      }
  1104.       if (prev == 0) goto badarg;
  1105.       if ((ranges = (int far *)farmemalloc(2L*entries)) == NULL) {
  1106.      static char far msg[] = {"Insufficient memory for ranges="};
  1107.      stopmsg(0,msg);
  1108.      return(-1);
  1109.      }
  1110.       rangeslen = entries;
  1111.       for (i = 0; i < rangeslen; ++i)
  1112.      ranges[i] = tmpranges[i];
  1113.       return 1;
  1114.       }
  1115.  
  1116.    if (strcmp(variable,"savename") == 0) {      /* savename=? */
  1117.       if (valuelen > 79) goto badarg;
  1118.       if (first_init || mode == 2)
  1119.      strcpy(savename,value);
  1120.       return 0;
  1121.       }
  1122.  
  1123.    if (strcmp(variable,"exitmode") == 0) {      /* exitmode=? */
  1124.       sscanf(value,"%x",&numval);
  1125.       exitmode = numval;
  1126.       return 0;
  1127.       }
  1128.  
  1129.    if (strcmp(variable,"textcolors") == 0) {
  1130.       parse_textcolors(value);
  1131.       return 0;
  1132.       }
  1133.  
  1134.    if (strcmp(variable,"potential") == 0) {     /* potential=? */
  1135.       k = 0;
  1136.       while (k < 3 && *value) {
  1137.          if(k==1)
  1138.             potparam[k] = atof(value);
  1139.          else
  1140.             potparam[k] = atoi(value);
  1141.          k++;
  1142.      if ((value = strchr(value,'/')) == NULL) k = 99;
  1143.      ++value;
  1144.      }
  1145.       pot16bit = 0;
  1146.       if (k < 99) {
  1147.      if (strcmp(value,"16bit")) goto badarg;
  1148.      pot16bit = 1;
  1149.      }
  1150.       return 1;
  1151.       }
  1152.  
  1153.    if (strcmp(variable,"params") == 0) {        /* params=?,? */
  1154.       if (totparms != floatparms || totparms > 4)
  1155.      goto badarg;
  1156.       for (k = 0; k < 4; ++k)
  1157.      param[k] = (k < totparms) ? floatval[k] : 0.0;
  1158.       initparams = 1;
  1159.       return 1;
  1160.       }
  1161.  
  1162.    if (strcmp(variable,"initorbit") == 0) {     /* initorbit=?,? */
  1163.       if(strcmp(value,"pixel")==0)
  1164.      useinitorbit = 2;
  1165.       else {
  1166.      if (totparms != 2 || floatparms != 2) goto badarg;
  1167.      initorbit[0] = floatval[0];
  1168.      initorbit[1] = floatval[1];
  1169.      useinitorbit = 1;
  1170.      }
  1171.       return 1;
  1172.       }
  1173.  
  1174.    if (strcmp(variable,"corners") == 0) {       /* corners=?,?,?,? */
  1175.       if (floatparms != totparms || (totparms != 4 && totparms != 6))
  1176.      goto badarg;
  1177.       usemag = 0;
  1178.       initcorners = 1;
  1179.       xx3rd = xxmin = floatval[0];
  1180.       xxmax =          floatval[1];
  1181.       yy3rd = yymin = floatval[2];
  1182.       yymax =          floatval[3];
  1183.       if (totparms == 6) {
  1184.      xx3rd =      floatval[4];
  1185.      yy3rd =      floatval[5];
  1186.      }
  1187.       return 1;
  1188.       }
  1189.  
  1190.    if (strcmp(variable,"center-mag") == 0) {    /* center-mag=?,?,? */
  1191.       double Xctr, Yctr,Magnification,Ratio,Height, Width,Radius;
  1192.       if (totparms != floatparms
  1193.     || (totparms != 0 && totparms != 3)
  1194.     || (totparms == 3 && floatval[2] <= 0.0))
  1195.      goto badarg;
  1196.       usemag = 1;
  1197.       if (totparms == 0) return 0;
  1198.       initcorners = 1;
  1199.       Xctr = floatval[0];
  1200.       Yctr = floatval[1];
  1201.       Magnification = floatval[2];
  1202.       Radius = 1.0 / Magnification;
  1203.       Ratio = .75;    /* inverse aspect ratio of screen  */
  1204.       /* calculate bounds */
  1205.       Height = 2.0 * Radius;
  1206.       Width = Height / Ratio;
  1207.       yymax = Yctr + Radius;
  1208.       yy3rd = yymin = Yctr - Radius;
  1209.       xxmax = Xctr + Width / 2.0;
  1210.       xx3rd = xxmin = Xctr - Width / 2.0;
  1211.       return 1;
  1212.       }
  1213.  
  1214.    if (strcmp(variable,"invert") == 0) {        /* invert=?,?,? */
  1215.       if (totparms != floatparms || (totparms != 1 && totparms != 3))
  1216.      goto badarg;
  1217.       invert = ((inversion[0] = floatval[0]) != 0.0) ? totparms : 0;
  1218.       if (totparms == 3) {
  1219.      inversion[1] = floatval[1];
  1220.      inversion[2] = floatval[2];
  1221.      }
  1222.       return 1;
  1223.       }
  1224.  
  1225.    if (strcmp(variable,"askvideo") == 0 ) {     /* askvideo=?   */
  1226.       if (yesnoval < 0) goto badarg;
  1227.       askvideo = yesnoval;
  1228.       return 0;
  1229.       }
  1230.  
  1231.    if (strcmp(variable,"ramvideo") == 0 )       /* ramvideo=?   */
  1232.       return 0; /* just ignore and return, for old time's sake */
  1233.  
  1234.    if (strcmp(variable,"float") == 0 ) {        /* float=? */
  1235.       if (yesnoval < 0) goto badarg;
  1236.       usr_floatflag = yesnoval;
  1237.       return 3;
  1238.       }
  1239.  
  1240.    if (strcmp(variable,"biomorph") == 0 ) {     /* biomorph=? */
  1241.       usr_biomorph = numval;
  1242.       return 1;
  1243.       }
  1244.  
  1245.    if (strcmp(variable,"orbitsave") == 0 ) {     /* orbitsave=? */
  1246.       if (yesnoval < 0) goto badarg;
  1247.       orbitsave = yesnoval;
  1248.       return 1;
  1249.       }
  1250.  
  1251.    if (strcmp(variable,"bailout") == 0 ) {      /* bailout=? */
  1252.       if (numval < 4 || numval > 32000) goto badarg;
  1253.       bailout = numval;
  1254.       return 1;
  1255.       }
  1256.  
  1257.    if (strcmp(variable,"symmetry") == 0 ) {     /* symmetry=? */
  1258.       if     (strcmp(value,"xaxis" )==0) forcesymmetry = XAXIS;
  1259.       else if(strcmp(value,"yaxis" )==0) forcesymmetry = YAXIS;
  1260.       else if(strcmp(value,"xyaxis")==0) forcesymmetry = XYAXIS;
  1261.       else if(strcmp(value,"origin")==0) forcesymmetry = ORIGIN;
  1262.       else if(strcmp(value,"pi"    )==0) forcesymmetry = PI_SYM;
  1263.       else if(strcmp(value,"none"  )==0) forcesymmetry = NOSYM;
  1264.       else goto badarg;
  1265.       return 1;
  1266.       }
  1267.  
  1268.    if (strcmp(variable,"printer") == 0 ) {      /* printer=? */
  1269.       if (parse_printer(value) < 0) goto badarg;
  1270.       return 0;
  1271.       }
  1272.  
  1273.    if (strcmp(variable,"printfile") == 0) {     /* print-to-file? SWT */
  1274.       if (valuelen > 79) goto badarg;
  1275.       Print_To_File = 1;
  1276.       strcpy(PrintName,value);
  1277.       return 0;
  1278.       }
  1279.  
  1280.    if(strcmp(variable, "colorps") == 0) {
  1281.       ColorPS = yesnoval;
  1282.       return(0);
  1283.       }
  1284.  
  1285.    if (strcmp(variable,"epsf") == 0) {          /* EPS type? SWT */
  1286.       Print_To_File = 1;
  1287.       EPSFileType = numval;
  1288.       Printer_Type = 5;
  1289.       if (strcmp(PrintName,"fract001.prn")==0)
  1290.      strcpy(PrintName,"fract001.eps");
  1291.       return 0;
  1292.       }
  1293.  
  1294.    if (strcmp(variable,"title") == 0) {         /* Printer title block? SWT */
  1295.       if (yesnoval < 0) goto badarg;
  1296.       Printer_Titleblock = yesnoval;
  1297.       return 0;
  1298.       }
  1299.  
  1300.    if (strcmp(variable,"translate") == 0) {     /* Translate color? SWT */
  1301.       Printer_ColorXlat=0;
  1302.       if (charval == 'y')
  1303.      Printer_ColorXlat=1;
  1304.       else if (numval > 1 || numval < -1)
  1305.      Printer_ColorXlat=numval;
  1306.       return 0;
  1307.       }
  1308.  
  1309.    if (strcmp(variable,"plotstyle") == 0) {     /* plot style? SWT */
  1310.       Printer_SStyle = numval;
  1311.       return 0;
  1312.       }
  1313.  
  1314.    if (strcmp(variable,"halftone") == 0) {      /* New halftoning? SWT */
  1315.       if (totparms != intparms) goto badarg;
  1316.       Printer_SetScreen=1;
  1317.       if ((totparms >  0) && ( intval[ 0] >= 0))
  1318.                       Printer_SFrequency = intval[ 0];
  1319.       if ((totparms >  1) && ( intval[ 1] >= 0))
  1320.                       Printer_SAngle     = intval[ 1];
  1321.       if ((totparms >  2) && ( intval[ 2] >= 0))
  1322.                       Printer_SStyle     = intval[ 2];
  1323.       if ((totparms >  3) && ( intval[ 3] >= 0))
  1324.                       Printer_RFrequency = intval[ 3];
  1325.       if ((totparms >  4) && ( intval[ 4] >= 0))
  1326.                       Printer_RAngle     = intval[ 4];
  1327.       if ((totparms >  5) && ( intval[ 5] >= 0))
  1328.                       Printer_RStyle     = intval[ 5];
  1329.       if ((totparms >  6) && ( intval[ 6] >= 0))
  1330.                       Printer_GFrequency = intval[ 6];
  1331.       if ((totparms >  7) && ( intval[ 7] >= 0))
  1332.                       Printer_GAngle     = intval[ 7];
  1333.       if ((totparms >  8) && ( intval[ 8] >= 0))
  1334.                       Printer_GStyle     = intval[ 8];
  1335.       if ((totparms >  9) && ( intval[ 9] >= 0))
  1336.                       Printer_BFrequency = intval[ 9];
  1337.       if ((totparms > 10) && ( intval[10] >= 0))
  1338.                       Printer_BAngle     = intval[10];
  1339.       if ((totparms > 11) && ( intval[11] >= 0))
  1340.                       Printer_BStyle     = intval[11];
  1341.       return 0;
  1342.       }
  1343.  
  1344.    if (strcmp(variable,"linefeed") == 0) {      /* Use LF for printer */
  1345.       if      (strcmp(value,"cr")   == 0) Printer_CRLF = 1;
  1346.       else if (strcmp(value,"lf")   == 0) Printer_CRLF = 2;
  1347.       else if (strcmp(value,"crlf") == 0) Printer_CRLF = 0;
  1348.       else goto badarg;
  1349.       return 0;
  1350.       }
  1351.  
  1352.    if (strcmp(variable,"comport") == 0 ) {      /* Set the COM parameters */
  1353.       if ((value=strchr(value,'/')) == NULL) goto badarg;
  1354.       switch (atoi(++value)) {
  1355.      case 110:  l = 0;   break;
  1356.      case 150:  l = 32;  break;
  1357.      case 300:  l = 64;  break;
  1358.      case 600:  l = 96;  break;
  1359.      case 1200: l = 128; break;
  1360.      case 2400: l = 160; break;
  1361.      case 4800: l = 192; break;
  1362.      case 9600:
  1363.      default:   l = 224; break;
  1364.      }
  1365.       if ((value=strchr(value,'/')) == NULL) goto badarg;
  1366.       for (k=0; k < strlen(value); k++) {
  1367.      switch (value[k]) {
  1368.         case '7':  l |= 2;  break;
  1369.         case '8':  l |= 3;  break;
  1370.         case 'o':  l |= 8;  break;
  1371.         case 'e':  l |= 24; break;
  1372.         case '2':  l |= 4;  break;
  1373.         }
  1374.      }
  1375. #ifndef WINFRACT
  1376.       _bios_serialcom(0,numval-1,l);
  1377. #endif
  1378.       return 0;
  1379.       }
  1380.  
  1381.    if (strcmp(variable,"sound") == 0 ) {        /* sound=? */
  1382.       soundflag = 0;
  1383.       if (strncmp(value,"ye",2) == 0)
  1384.      soundflag = -1;
  1385.       if (charval == 'x')
  1386.      soundflag = 1;
  1387.       if (charval == 'y')
  1388.      soundflag = 2;
  1389.       if (charval == 'z')
  1390.      soundflag = 3;
  1391.       return 0;
  1392.       }
  1393.  
  1394.    if (strcmp(variable,"hertz") == 0) {         /* Hertz=? */
  1395.       if (numval < 200 || numval > 10000) goto badarg;
  1396.       basehertz = numval;
  1397.       return 0;
  1398.       }
  1399.  
  1400.    if (strcmp(variable,"periodicity") == 0 ) {  /* periodicity=? */
  1401.       usr_periodicitycheck=1;
  1402.       if (charval == 'n')
  1403.      usr_periodicitycheck=0;
  1404.       else if (charval == 'y')
  1405.      usr_periodicitycheck=1;
  1406.       else if (charval == 's')   /* 's' for 'show' */
  1407.      usr_periodicitycheck=-1;
  1408.       else if(numval == NONNUMERIC)
  1409.      goto badarg;
  1410.       else if(numval != 0)
  1411.      usr_periodicitycheck=numval;
  1412.       return 1;
  1413.       }
  1414.  
  1415.    if (strcmp(variable,"logmap") == 0 ) {       /* logmap=? */
  1416.       if (charval == 'y')
  1417.      LogFlag = 1;                /* palette is logarithmic */
  1418.       else if (charval == 'n')
  1419.      LogFlag = 0;
  1420.       else if (charval == 'o')
  1421.      LogFlag = -1;                /* old log palette */
  1422.       else
  1423.      LogFlag = numval;
  1424.       return 1;
  1425.       }
  1426.  
  1427.    if (strcmp(variable,"debugflag") == 0
  1428.      || strcmp(variable,"debug") == 0) {        /* internal use only */
  1429.       debugflag = numval;
  1430.       timerflag = debugflag & 1;        /* separate timer flag */
  1431.       debugflag -= timerflag;
  1432.       return 0;
  1433.       }
  1434.  
  1435.    if (strcmp(variable, "rseed") == 0) {
  1436.       rseed = numval;
  1437.       rflag = 1;
  1438.       return 1;
  1439.       }
  1440.  
  1441.    if (strcmp(variable, "orbitdelay") == 0) {
  1442.       orbit_delay = numval;
  1443.       return 0;
  1444.       }
  1445.  
  1446.    if (strcmp(variable, "showdot") == 0) {
  1447.       showdot=numval;
  1448.       if(showdot<0)
  1449.          showdot=0;
  1450.       return 0;
  1451.       }
  1452.  
  1453.    if (strcmp(variable, "decomp") == 0) {
  1454.       if (totparms != intparms || totparms < 1) goto badarg;
  1455.       decomp[0] = intval[0];
  1456.       decomp[1] = 0;
  1457.       if (totparms > 1) /* backward compatibility */
  1458.      bailout = decomp[1] = intval[1];
  1459.       return 1;
  1460.       }
  1461.  
  1462.    if (strcmp(variable, "distest") == 0) {
  1463.       if (totparms != intparms || totparms < 1) goto badarg;
  1464.       usr_distest = intval[0];
  1465.       distestwidth = 71;
  1466.       if (totparms > 1)
  1467.      distestwidth = intval[1];
  1468.       return 1;
  1469.       }
  1470.  
  1471.    if (strcmp(variable,"formulafile") == 0) {   /* formulafile=? */
  1472.       if (valuelen > 79) goto badarg;
  1473.       strcpy(FormFileName,value);
  1474.       return 1;
  1475.       }
  1476.  
  1477.    if (strcmp(variable,"formulaname") == 0) {   /* formulaname=? */
  1478.       if (valuelen > ITEMNAMELEN) goto badarg;
  1479.       strcpy(FormName,value);
  1480.       return 1;
  1481.       }
  1482.  
  1483.    if (strcmp(variable,"lfile") == 0) {
  1484.       if (valuelen > 79) goto badarg;
  1485.       strcpy(LFileName,value);
  1486.       return 1;
  1487.       }
  1488.  
  1489.    if (strcmp(variable,"lname") == 0) {
  1490.       if (valuelen > ITEMNAMELEN) goto badarg;
  1491.       strcpy(LName,value);
  1492.       return 1;
  1493.       }
  1494.  
  1495.    if (strcmp(variable,"ifsfile") == 0) {
  1496.       if (valuelen > 79) goto badarg;
  1497.       strcpy(IFSFileName,value);
  1498.       reset_ifs_defn();
  1499.       return 1;
  1500.       }
  1501.  
  1502.    if (strcmp(variable,"ifs") == 0
  1503.      || strcmp(variable,"ifs3d") == 0) {        /* ifs3d for old time's sake */
  1504.       if (valuelen > ITEMNAMELEN) goto badarg;
  1505.       strcpy(IFSName,value);
  1506.       reset_ifs_defn();
  1507.       return 1;
  1508.       }
  1509.  
  1510.    if (strcmp(variable,"parmfile") == 0) {
  1511.       if (valuelen > 79) goto badarg;
  1512.       strcpy(CommandFile,value);
  1513.       return 0;
  1514.       }
  1515.  
  1516.    if (strcmp(variable,"stereo") == 0) {        /* stereo=? */
  1517.       if ((numval<0) || (numval>3)) goto badarg;
  1518.       glassestype = numval;
  1519.       return 3;
  1520.       }
  1521.  
  1522.    if (strcmp(variable,"rotation") == 0) {      /* rotation=?/?/? */
  1523.       if (totparms != 3 || intparms != 3) goto badarg;
  1524.       XROT = intval[0];
  1525.       YROT = intval[1];
  1526.       ZROT = intval[2];
  1527.       return 3;
  1528.       }
  1529.  
  1530.    if (strcmp(variable,"perspective") == 0) {   /* perspective=? */
  1531.       if (numval == NONNUMERIC) goto badarg;
  1532.       ZVIEWER = numval;
  1533.       return 3;
  1534.       }
  1535.  
  1536.    if (strcmp(variable,"xyshift") == 0) {       /* xyshift=?/?  */
  1537.       if (totparms != 2 || intparms != 2) goto badarg;
  1538.       XSHIFT = intval[0];
  1539.       YSHIFT = intval[1];
  1540.       return 3;
  1541.       }
  1542.  
  1543.    if (strcmp(variable,"interocular") == 0) {   /* interocular=? */
  1544.       eyeseparation = numval;
  1545.       return 3;
  1546.       }
  1547.  
  1548.    if (strcmp(variable,"converge") == 0) {      /* converg=? */
  1549.       xadjust = numval;
  1550.       return 3;
  1551.       }
  1552.  
  1553.    if (strcmp(variable,"crop") == 0) {          /* crop=? */
  1554.       if (totparms != 4 || intparms != 4
  1555.     || intval[0] < 0 || intval[0] > 100
  1556.     || intval[1] < 0 || intval[1] > 100
  1557.     || intval[2] < 0 || intval[2] > 100
  1558.     || intval[3] < 0 || intval[3] > 100)
  1559.       goto badarg;
  1560.       red_crop_left   = intval[0];
  1561.       red_crop_right  = intval[1];
  1562.       blue_crop_left  = intval[2];
  1563.       blue_crop_right = intval[3];
  1564.       return 3;
  1565.       }
  1566.  
  1567.    if (strcmp(variable,"bright") == 0) {        /* bright=? */
  1568.       if (totparms != 2 || intparms != 2) goto badarg;
  1569.       red_bright  = intval[0];
  1570.       blue_bright = intval[1];
  1571.       return 3;
  1572.       }
  1573.  
  1574.    if (strcmp(variable,"xyadjust") == 0) {      /* trans=? */
  1575.       if (totparms != 2 || intparms != 2) goto badarg;
  1576.       xtrans = intval[0];
  1577.       ytrans = intval[1];
  1578.       return 3;
  1579.       }
  1580.  
  1581.    if (strcmp(variable,"3d") == 0) {            /* 3d=?/?/..    */
  1582.       if (yesnoval < 0) goto badarg;
  1583.       display3d = yesnoval;
  1584.       initvars_3d();
  1585.       return (display3d) ? 6 : 2;
  1586.       }
  1587.  
  1588.    if (strcmp(variable,"sphere") == 0 ) {       /* sphere=? */
  1589.       if (yesnoval < 0) goto badarg;
  1590.       SPHERE = yesnoval;
  1591.       return 2;
  1592.       }
  1593.  
  1594.    if (strcmp(variable,"scalexyz") == 0) {      /* scalexyz=?/?/? */
  1595.       if (totparms < 2 || intparms != totparms) goto badarg;
  1596.       XSCALE = intval[0];
  1597.       YSCALE = intval[1];
  1598.       if (totparms > 2) ROUGH = intval[2];
  1599.       return 2;
  1600.       }
  1601.  
  1602.    /* "rough" is really scale z, but we add it here for convenience */
  1603.    if (strcmp(variable,"roughness") == 0) {     /* roughness=?  */
  1604.       ROUGH = numval;
  1605.       return 2;
  1606.       }
  1607.  
  1608.    if (strcmp(variable,"waterline") == 0) {     /* waterline=?  */
  1609.       if (numval<0) goto badarg;
  1610.       WATERLINE = numval;
  1611.       return 2;
  1612.       }
  1613.  
  1614.    if (strcmp(variable,"filltype") == 0) {      /* filltype=?   */
  1615.       if (numval < -1 || numval > 6) goto badarg;
  1616.       FILLTYPE = numval;
  1617.       return 2;
  1618.       }
  1619.  
  1620.    if (strcmp(variable,"lightsource") == 0) {   /* lightsource=?/?/? */
  1621.       if (totparms != 3 || intparms != 3) goto badarg;
  1622.       XLIGHT = intval[0];
  1623.       YLIGHT = intval[1];
  1624.       ZLIGHT = intval[2];
  1625.       return 2;
  1626.       }
  1627.  
  1628.    if (strcmp(variable,"smoothing") == 0) {     /* smoothing=?  */
  1629.       if (numval<0) goto badarg;
  1630.       LIGHTAVG = numval;
  1631.       return 2;
  1632.       }
  1633.  
  1634.    if (strcmp(variable,"latitude") == 0) {      /* latitude=?/? */
  1635.       if (totparms != 2 || intparms != 2) goto badarg;
  1636.       THETA1 = intval[0];
  1637.       THETA2 = intval[1];
  1638.       return 2;
  1639.       }
  1640.  
  1641.    if (strcmp(variable,"longitude") == 0) {     /* longitude=?/? */
  1642.       if (totparms != 2 || intparms != 2) goto badarg;
  1643.       PHI1 = intval[0];
  1644.       PHI2 = intval[1];
  1645.       return 2;
  1646.       }
  1647.  
  1648.    if (strcmp(variable,"radius") == 0) {        /* radius=? */
  1649.       if (numval < 0) goto badarg;
  1650.       RADIUS = numval;
  1651.       return 2;
  1652.       }
  1653.  
  1654.    if (strcmp(variable,"transparent") == 0) {   /* transparent? */
  1655.       if (totparms != intparms || totparms < 1) goto badarg;
  1656.       transparent[1] = transparent[0] = intval[0];
  1657.       if (totparms > 1) transparent[1] = intval[1];
  1658.       return 2;
  1659.       }
  1660.  
  1661.    if (strcmp(variable,"preview") == 0) {       /* preview? */
  1662.       if (yesnoval < 0) goto badarg;
  1663.       preview = yesnoval;
  1664.       return 2;
  1665.       }
  1666.  
  1667.    if (strcmp(variable,"showbox") == 0) {       /* showbox? */
  1668.       if (yesnoval < 0) goto badarg;
  1669.       showbox = yesnoval;
  1670.       return 2;
  1671.       }
  1672.  
  1673.    if (strcmp(variable,"coarse") == 0) {        /* coarse=? */
  1674.       if (numval < 3 || numval > 2000) goto badarg;
  1675.       previewfactor = numval;
  1676.       return 2;
  1677.       }
  1678.  
  1679.    if (strcmp(variable,"randomize") == 0) {     /* RANDOMIZE=? */
  1680.       if (numval<0 || numval>7) goto badarg;
  1681.       RANDOMIZE = numval;
  1682.       return 2;
  1683.       }
  1684.  
  1685.    if (strcmp(variable,"ambient") == 0) {       /* ambient=? */
  1686.       if (numval<0||numval>100) goto badarg;
  1687.       Ambient = numval;
  1688.       return 2;
  1689.       }
  1690.  
  1691.    if (strcmp(variable,"haze") == 0) {          /* haze=? */
  1692.       if (numval<0||numval>100) goto badarg;
  1693.       haze = numval;
  1694.       return 2;
  1695.       }
  1696.  
  1697.    if (strcmp(variable,"fullcolor") == 0) {     /* fullcolor=? */
  1698.       if (yesnoval < 0) goto badarg;
  1699.       Targa_Out = yesnoval;
  1700.       return 2;
  1701.       }
  1702.    if (strcmp(variable,"targa_out") == 0) {     /* Targa Out? */
  1703.       if (yesnoval < 0) goto badarg;
  1704.       Targa_Out = yesnoval;
  1705.       return 2;
  1706.       }
  1707.  
  1708.    if (strcmp(variable,"targa_overlay") == 0) {         /* Targa Overlay? */
  1709.       if (yesnoval < 0) goto badarg;
  1710.       Targa_Overlay = yesnoval;
  1711.       return 2;
  1712.       }
  1713.  
  1714.    if (strcmp(variable,"background") == 0) {     /* background=?/? */
  1715.       if (totparms != 3 || intparms != 3) goto badarg;
  1716.                 for (i=0;i<3;i++)
  1717.                         if (intval[i] & 0xff)
  1718.                                 goto badarg;
  1719.       back_color[0] = intval[0];
  1720.       back_color[1] = intval[1];
  1721.       back_color[2] = intval[2];
  1722.       return 2;
  1723.       }
  1724.  
  1725.    if (strcmp(variable,"lightname") == 0) {     /* lightname=?   */
  1726.       if (valuelen > 79) goto badarg;
  1727.       if (first_init || mode == 2)
  1728.      strcpy(light_name,value);
  1729.       return 0;
  1730.       }
  1731.  
  1732.    if (strcmp(variable,"ray") == 0) {           /* RAY=? */
  1733.       if (numval < 0 || numval > 6) goto badarg;
  1734.       RAY = numval;
  1735.       return 2;
  1736.       }
  1737.  
  1738.    if (strcmp(variable,"brief") == 0) {         /* BRIEF? */
  1739.       if (yesnoval < 0) goto badarg;
  1740.       BRIEF = yesnoval;
  1741.       return 2;
  1742.       }
  1743.  
  1744.  
  1745. badarg:
  1746.    argerror(curarg);
  1747.    return(-1);
  1748.  
  1749. }
  1750.  
  1751. /* Some routines broken out of above so compiler doesn't run out of heap: */
  1752.  
  1753. static void parse_textcolors(char *value)
  1754. {
  1755.    int i,j,k,hexval;
  1756.    if (strcmp(value,"mono") == 0) {
  1757.       for (k = 0; k < sizeof(txtcolor); ++k)
  1758.      txtcolor[k] = BLACK*16+WHITE;
  1759.    /* C_HELP_CURLINK = C_PROMPT_INPUT = C_CHOICE_CURRENT = C_GENERAL_INPUT
  1760.              = C_AUTHDIV1 = C_AUTHDIV2 = WHITE*16+BLACK; */
  1761.       txtcolor[6] = txtcolor[12] = txtcolor[13] = txtcolor[14] = txtcolor[20]
  1762.           = txtcolor[27] = txtcolor[28] = WHITE*16+BLACK;
  1763.       /* C_TITLE = C_HELP_HDG = C_HELP_LINK = C_PROMPT_HI = C_CHOICE_SP_KEYIN
  1764.          = C_GENERAL_HI = C_DVID_HI = C_STOP_ERR
  1765.          = C_STOP_INFO = BLACK*16+L_WHITE; */
  1766.       txtcolor[0] = txtcolor[2] = txtcolor[5] = txtcolor[11] = txtcolor[16]
  1767.           = txtcolor[17] = txtcolor[22] = txtcolor[24]
  1768.           = txtcolor[25] = BLACK*16+L_WHITE;
  1769.       }
  1770.    else {
  1771.       k = 0;
  1772.       while ( k < sizeof(txtcolor)) {
  1773.      if (*value == 0) break;
  1774.      if (*value != '/') {
  1775.         sscanf(value,"%x",&hexval);
  1776.         i = (hexval / 16) & 7;
  1777.         j = hexval & 15;
  1778.         if (i == j || (i == 0 && j == 8)) /* force contrast */
  1779.            j = 15;
  1780.         txtcolor[k] = i * 16 + j;
  1781.         if ((value = strchr(value,'/')) == NULL) break;
  1782.         }
  1783.      ++value;
  1784.      ++k;
  1785.      }
  1786.       }
  1787. }
  1788.  
  1789. static int parse_colors(char *value)
  1790. {
  1791.    int i,j,k;
  1792.    if (*value == '@') {
  1793.       if (strlen(value) > 80 || ValidateLuts(&value[1]) != 0) goto badcolor;
  1794.       if (display3d) {
  1795.         mapset = 1;
  1796.         strcpy(MAP_name,&value[1]);
  1797.         }
  1798.       else {
  1799.         strcpy(colorfile,&value[1]);
  1800.         colorstate = 2;
  1801.         }
  1802.       }
  1803.    else {
  1804.       int smooth;
  1805.       i = smooth = 0;
  1806.       while (*value) {
  1807.      if (i >= 256) goto badcolor;
  1808.      if (*value == '<') {
  1809.         if (i == 0 || smooth
  1810.           || (smooth = atoi(value+1)) < 2
  1811.           || (value = strchr(value,'>')) == NULL)
  1812.            goto badcolor;
  1813.         i += smooth;
  1814.         ++value;
  1815.         }
  1816.      else {
  1817.         for (j = 0; j < 3; ++j) {
  1818.            if ((k = *(value++)) < '0')  goto badcolor;
  1819.            else if (k <= '9')       k -= '0';
  1820.            else if (k < 'A')            goto badcolor;
  1821.            else if (k <= 'Z')       k -= ('A'-10);
  1822.            else if (k < '_' || k > 'z') goto badcolor;
  1823.            else            k -= ('_'-36);
  1824.            dacbox[i][j] = k;
  1825.            if (smooth) {
  1826.           int start,spread,cnum;
  1827.           start = i - (spread = smooth + 1);
  1828.           cnum = 0;
  1829.           if ((k - (int)dacbox[start][j]) == 0) {
  1830.              while (++cnum < spread)
  1831.             dacbox[start+cnum][j] = k;
  1832.              }
  1833.           else {
  1834.              while (++cnum < spread)
  1835.             dacbox[start+cnum][j] =
  1836.                ( cnum         *dacbox[i][j]
  1837.                + (i-(start+cnum))*dacbox[start][j]
  1838.                + spread/2 )
  1839.                / spread;
  1840.              }
  1841.           }
  1842.            }
  1843.         smooth = 0;
  1844.         ++i;
  1845.         }
  1846.      }
  1847.       if (smooth) goto badcolor;
  1848.       while (i < 256)  { /* zap unset entries */
  1849.      dacbox[i][0] = dacbox[i][1] = dacbox[i][2] = 40;
  1850.      ++i;
  1851.      }
  1852.       colorstate = 1;
  1853.       }
  1854.    colorpreloaded = 1;
  1855.    return(0);
  1856. badcolor:
  1857.    return(-1);
  1858. }
  1859.  
  1860. static int parse_printer(char *value)
  1861. {
  1862.    int k;
  1863.    if (value[0]=='h' && value[1]=='p')
  1864.       Printer_Type=1;                 /* HP LaserJet           */
  1865.    if (value[0]=='i' && value[1]=='b')
  1866.       Printer_Type=2;                 /* IBM Graphics           */
  1867.    if (value[0]=='e' && value[1]=='p')
  1868.       Printer_Type=2;                 /* Epson (model?)           */
  1869.    if (value[0]=='c' && value[1]=='o')
  1870.       Printer_Type=3;                 /* Star (Epson-Comp?) color */
  1871.    if (value[0]=='p') {
  1872.       if (value[1]=='a')
  1873.      Printer_Type=4;             /* HP Paintjet (color)    */
  1874.       if ((value[1]=='o' || value[1]=='s')) {
  1875.      Printer_Type=5;             /* PostScript  SWT */
  1876.      if (value[2]=='h' || value[2]=='l')
  1877.         Printer_Type=6;
  1878.      }
  1879.       if (value[1]=='l')
  1880.      Printer_Type=7;             /* HP Plotter (semi-color) */
  1881.       }
  1882.    if (Printer_Type == 1)             /* assume low resolution */
  1883.       Printer_Resolution = 75;
  1884.    else
  1885.       Printer_Resolution = 60;
  1886.    if (EPSFileType > 0)              /* EPS save - force type 5 */
  1887.       Printer_Type = 5;
  1888.    if ((Printer_Type == 5) || (Printer_Type == 6))
  1889.       Printer_Resolution = 150;          /* PostScript def. res. */
  1890.    if ((value=strchr(value,'/'))) {
  1891.       if ((k=atoi(++value)) >= 0) Printer_Resolution=k;
  1892.       if ((value=strchr(value,'/'))) {
  1893.      if ((k=atoi(++value))> 0) LPTNumber = k;
  1894.      if (k < 0) {
  1895.         Print_To_File = 1;
  1896.         LPTNumber = 1;
  1897.         }
  1898.      }
  1899.       }
  1900.    return(0);
  1901. }
  1902.  
  1903.  
  1904.  
  1905. static void argerror(char *badarg)    /* oops. couldn't decode this */
  1906. {
  1907.    static char far argerrmsg1[]={"\
  1908. Oops. I couldn't understand the argument:\n  "};
  1909.    static char far argerrmsg2[]={"\n\n\
  1910. (see the Startup Help screens or documentation for a complete\n\
  1911.  argument list with descriptions)"};
  1912.    char msg[300];
  1913.    if (strlen(badarg) > 70) badarg[70] = 0;
  1914.    if (active_system == 0 /* DOS */
  1915.      && first_init)      /* & this is 1st call to cmdfiles */
  1916.       sprintf(msg,"%Fs%s%Fs",argerrmsg1,badarg,argerrmsg2);
  1917.    else
  1918.       sprintf(msg,"%Fs%s",argerrmsg1,badarg);
  1919.    stopmsg(0,msg);
  1920. }
  1921.  
  1922. void set_3d_defaults()
  1923. {
  1924.    ENTER_OVLY(OVLY_CMDFILES);
  1925.    ROUGH     = 30;
  1926.    WATERLINE = 0;
  1927.    ZVIEWER   = 0;
  1928.    XSHIFT    = 0;
  1929.    YSHIFT    = 0;
  1930.    xtrans    = 0;
  1931.    ytrans    = 0;
  1932.    LIGHTAVG  = 0;
  1933.    Ambient   = 20;
  1934.    RANDOMIZE = 0;
  1935.    haze      = 0;
  1936.    back_color[0] = 51; back_color[1] = 153; back_color[2] = 200;
  1937.    if(SPHERE) {
  1938.       PHI1    =  180;
  1939.       PHI2    =  0;
  1940.       THETA1    =  -90;
  1941.       THETA2    =  90;
  1942.       RADIUS    =  100;
  1943.       FILLTYPE    = 2;
  1944.       XLIGHT    = 1;
  1945.       YLIGHT    = 1;
  1946.       ZLIGHT    = 1;
  1947.       }
  1948.    else {
  1949.       XROT    = 60;
  1950.       YROT    = 30;
  1951.       ZROT    = 0;
  1952.       XSCALE    = 90;
  1953.       YSCALE    = 90;
  1954.       FILLTYPE    = 0;
  1955.       if (active_system != 0)
  1956.      FILLTYPE = 2;
  1957.       XLIGHT    = 1;
  1958.       YLIGHT    = -1;
  1959.       ZLIGHT    = 1;
  1960.       }
  1961.     EXIT_OVLY;
  1962. }
  1963.